#include"Protocol.hpp"
#include"Socket.hpp"
#include<iostream>
#include<string>
#include<unistd.h>
using namespace std;

int main(int argc,char* argv[])
{
    if (argc != 3)
    {
        cout << "Usage:\n     ./udp_echo_server <ip> <port>" << endl;
        return 0;
    }

    string serverip = argv[1];
    uint16_t serverport = atoi(argv[2]);

    Network::Socket* s=new Network::TcpSocket();
    bool m=s->BuildconnectSocketMethod(serverip,serverport);
    if(!m)
    {
        cerr<<"connect failed"<<serverip<<":"<<serverport<<endl;
        return 0;
    }
    cout<<"connect success"<<serverip<<":"<<serverport<<endl;

    string message="hello world";
    write(s->GetSockfd(),message.c_str(),message.size());


    unique_ptr<Factory> factory=make_unique<Factory>();//????

    shared_ptr<Request> req=factory->BuildRequest(10,20,'+');

    while(true)
    {
        req->Inc();
        send(s->GetSockfd(),&(*req),sizeof(*req),0);
        sleep(1);
    }

    s->CloseSocket();
    sleep(10);
    return 0;
}
